import { defineStore } from "pinia";
import {
  IDictionaryCategoryDto,
  InUser,
  IOrganizationUnitWithDetailsDto,
  ISeverityLevelDto,
} from "vue-kst-auth";
// type ValueOf<T> = T[keyof T];
/** 基础数据状态管理 */
interface InStoreBaseData {
  /** 基本请求路径 */
  baseUrl: string;
  /** 授权 */
  grantedPolicies: {
    [key: string]: boolean | undefined;
  };
  /** 部门人员 */
  organizationUsers: Array<{
    organizationUnits: IOrganizationUnitWithDetailsDto;
    users: InUser[];
  }>;
  /** 部门 */
  organizationUnit: IOrganizationUnitWithDetailsDto[];
  /** 人员 */
  users: InUser[];
  /** 严重等级 */
  severityLevel: ISeverityLevelDto[];
  /** 资产分类 */
  assetTypes: IDictionaryCategoryDto[];
  /** 位置 */
  positions: IDictionaryCategoryDto[];
  /** 当前用户所在部门 */
  userInOrganiza: IOrganizationUnitWithDetailsDto[];
  /** 资产状态 */
  assetStatus: IDictionaryCategoryDto[];
  /** 缩放比例 */
  scaleX: number;
  /** 可视化高度 */
  clientHeight: number;
  /**token */
  token: string;
}
export const useBaseDataStore = defineStore("baseData", {
  state: (): InStoreBaseData => {
    return {
      baseUrl: "",
      grantedPolicies: {},
      organizationUnit: [],
      organizationUsers: [],
      users: [],
      severityLevel: [],
      assetStatus: [],
      assetTypes: [],
      positions: [],
      userInOrganiza: [],
      scaleX: 1,
      clientHeight: 1000,
      token: ''
    };
  },
  getters: {
    getBaseData: (state) => {
      return (key: keyof InStoreBaseData) => state[key];
    },
  },
  actions: {
    setBaseDataApi(payload: { key: keyof InStoreBaseData; value: any }) {
      (this.$state as any)[payload.key] = payload.value;
    },
  },
});
